% TEST_ID: LANG-EXPAND-0074
% CATEGORY: stdlib/arithmetic_ops/accumulate
% 测试 movsum 函数

function test_movsum

    A = [4 8 6 -1 -2 -3 -1 3 4 5];
    M = movsum(A, 3);
    result = [12 18 13 3 -6 -6 -1 6 12 9];
    assert_istrue(M, result);

    A = [4 8 6 -1 -2 -3 -1 3 4 5];
    M = movsum(A, [2 0]);
    result = [4 12 18 13 3 -6 -6 -1 6 12];
    assert_istrue(M, result);

    A = [4 8 6; -1 -2 -3; -1 3 4];
    M = movsum(A, 3, 2);
    result = [12 18 14
        -3 -6 -5
        2 6 7];
    assert_istrue(M, result);

    A = [4 8 NaN -1 -2 -3 NaN 3 4 5];
    M = movsum(A, 3, 'omitnan');
    result = [12 12 7 -3 -6 -5 0 7 12 9];
    assert_istrue(M, result);

    A = [4 8 6 -1 -2 -3 -1 3 4 5];
    M = movsum(A, 3, 'Endpoints', 'discard');
    result = [18 13 3 -6 -6 -1 6 12];
    assert_istrue(M, result);

    A = [4 8 6 -1 -2 -3 -1 3 4 5];
    M = movsum(A, 3, 'Endpoints', 1 + 1i);
    result = [13.000000000000000 + 1.000000000000000i 18.000000000000000 + 0.000000000000000i 13.000000000000000 + 0.000000000000000i 3.000000000000000 + 0.000000000000000i -6.000000000000000 + 0.000000000000000i ...
        -6.000000000000000 + 0.000000000000000i -1.000000000000000 + 0.000000000000000i 6.000000000000000 + 0.000000000000000i 12.000000000000000 + 0.000000000000000i 10.000000000000000 + 1.000000000000000i];
    assert_istrue(M, result);

    A = [1 2 3];
    M = movsum(A, 3, 'endpoints', int8(1 + i));
    result = [4.0000 + 1.0000i 6.0000 + 0.0000i 6.0000 + 1.0000i];
    assert_istrue(M, result);

    assert(isempty(movsum([], 1)));

    M = movsum(ones(0, 3, 4), 3);
    assert(isempty(M));
    assert(isequal(size(M), [0, 3, 4]));
    M = movsum(ones(3, 0, 4), 3, 'endpoints', 'discard');
    assert(isempty(M));
    assert(isequal(size(M), [1, 0, 4]));

end



function assert_istrue(x, y)
    assert(isequal(x, y));
end